<template>
  <div class="content-box">
    <nav-title title="紧急联系人" />
    <div class="line">
      <span class="important"></span>
      <div class="label">姓名</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cName" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">性别</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="sexVal" v-model="emergen.cTactPerSex"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">与本人关系</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="relVal" v-model="emergen.cRelationTact"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">工作单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cCompany" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">办公电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone2" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">手机电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone1" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">住宅电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">联系地址</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cAddress" readonly="readonly">
      </div>
    </div>

    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { getDicItem,savePtack } from '../../../api/api'
import { json2Form } from '../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getsexDic()
    this.getrelDic()
  },
  data() {
    return {
      emergen:{
        emplid: '10070226',
        cTransactionNbr:''
      },
      showOr:true,
      sexVal:[],
      relVal:[],
    }
  },
  created() {
    this.getEmers()
  },
  methods: {
    save() {
      this.emergen.cTactPerSex = this.emergen.cTactPerSex[0]
      this.emergen.cRelationTact = this.emergen.cRelationTact[0]
      this.emergen.cModStauts = 'U'
      console.log(this.emergen)
      savePtack(json2Form(this.emergen)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '奥克斯',
            content: '保存成功',
            onHide () {
              that.$router.push({
                name: 'userBase',
                params:{
                  cnta: that.emergen.cTransactionNbr
                }
              });
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
        console.log(res)
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },

    //性别
      getsexDic(){
        this.sexVal = []
        let params = {
          fileName: 'SEX'
        }
        getDicItem(params).then(res => {
          res.retData.forEach((val) => {
            this.sexVal.push({value: val.xlatshortname, key: val.fieldvalue})
          });
        }).catch(res => {

        })
      },

      //关系
      getrelDic(){
        this.relVal = []
        let params = {
          fileName: 'C_RELATION_TACT'
        }
        getDicItem(params).then(res => {
          res.retData.forEach((val) => {
            this.relVal.push({value: val.xlatshortname, key: val.fieldvalue})
          });
        }).catch(res => {

        })
      },

    getEmers() {
      if(this.$route.params.emeg){
        this.emergen = this.$route.params.emeg
        this.emergen.cTransactionNbr = this.$route.params.ctn
        console.log(this.emergen)
        if(!this.emergen.cTransactionNbr){
          this.showOr = false
        }
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>
